const Router = require('koa-router')
const router = new Router({ prefix: '/api/role' })
const { Role } = require('../models/model')

router.post('/save', async (ctx, next) => {
  const body = ctx.request.body
  const data = await Role.create({
    name: body.name,
    description: body.description
  })
  if (data) {
    ctx.status = 200
    ctx.body = {
      code: 200,
      msg: '新增角色成功',
      data: data
    }
  } else {
    ctx.status = 0
    ctx.body = {
      code: 0,
      msg: '新增角色失败',
      data: data
    }
  }
})


module.exports = router